import { Column, Entity, OneToMany, PrimaryGeneratedColumn, Tree, TreeChildren, TreeParent } from 'typeorm';
import { ProductEntity } from '../../products/entities/shop-products.entity';

@Entity('shop-categories')
@Tree('closure-table')
export class CategoryEntity {
  @PrimaryGeneratedColumn()
  id: number;

  @Column({ length: 100, comment: '分类名称' })
  name: string;

  @Column({ nullable: true, comment: '分类图片' })
  categoryImg: string;

  @TreeChildren()
  children: CategoryEntity[];

  @TreeParent()
  parent: CategoryEntity;

  @OneToMany(() => ProductEntity, (product) => product.category)
  products: ProductEntity[];
}
